package com.example.controller;


import com.example.bean.Address;
import com.example.bean.ResultVo;
import com.example.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AddressController {
    /**
     *
     */
    @Autowired
    AddressService addressService;
//查询所有
    @RequestMapping(value = "/api/getFindAll", method = RequestMethod.POST)
    @CrossOrigin
    public List<Address> getFindAll(@RequestParam("uId") int uId){
        return  addressService.findAll(uId);
    }

    //修改地址
    @RequestMapping(value = "/api/modifUpdateAddress", method = RequestMethod.POST)
    @CrossOrigin
    public ResultVo modifUpdateAddress(@RequestParam("aId") int aId,
                                       @RequestParam("rName") String rName,
                                       @RequestParam("rPhone") String rPhone,
                                       @RequestParam("rAddress") String rAddress){
        return addressService.modifUpdateAddress(aId,rName,rPhone,rAddress);
    }
    //增加地址
    @RequestMapping(value = "/api/addAddress", method = RequestMethod.POST)
    @CrossOrigin
    public Boolean addAddress(@RequestBody Address address){
        return  addressService.addAddress1(address);
    }
    //删除地址
    @RequestMapping(value = "/api/deleteAddress", method = RequestMethod.POST)
    @CrossOrigin
    public Boolean deleteAddress(@RequestParam("aId") int aId){
        return addressService.deleteAddress1(aId);
    }

    //查询用户的默认地址
    @RequestMapping("/api/findDefaultAddress")
    @CrossOrigin
    public Address findDefaultAddress(@RequestParam ("uid")int uid){
        return addressService.findDefaultAddress(uid);
    }
}
